import json
from pathlib import Path
from datetime import datetime

def save_transcript(audio_name: str, transcript: str, audio_dir: Path, model_size: str = "unknown"):

    audio_dir.mkdir(parents=True, exist_ok=True)


    current_time = datetime.now()
    timestamp_str = current_time.strftime("%Y-%m-%d %H:%M:%S")


    filename_timestamp = current_time.strftime("%Y%m%d_%H%M%S")
    json_name = f"transcript_{filename_timestamp}.json"
    json_path = audio_dir / json_name

    data = {
        "audio_file": audio_name,
        "transcript": transcript,
        "model": model_size,
        "transcription_time": timestamp_str
    }

    with open(json_path, 'w', encoding='utf-8') as f:
        json.dump(data, f, ensure_ascii=False, indent=2)

    print(f"✅ 转录结果已保存为: {json_path}")


    return str(json_path)
